package de.fmannan.addbook.views;

import org.apache.log4j.Logger;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

import de.fmannan.addbook.MyImageRegistry;
import de.fmannan.addbook.domainmodel.Contact;

public class TableViewLabelProvider extends LabelProvider implements
		ITableLabelProvider {

	private static final Logger log = Logger.getLogger(TableViewLabelProvider.class);

	public String getText(Object obj) {
		return obj.toString();
	}

	@Override
	/**
	 * Returns the correct image for each column-header
	 */
	public Image getColumnImage(Object element, int columnIndex) {		
		switch(columnIndex) {		
			case 0:
				return MyImageRegistry.getImageRegistry().get(
						MyImageRegistry.CONTACT_ICON);
			case 1:
				return MyImageRegistry.getImageRegistry().get(
						MyImageRegistry.HOME_ICON);
			case 2:
				return MyImageRegistry.getImageRegistry().get(
						MyImageRegistry.OFFICE_ICON);
			case 3:
				return MyImageRegistry.getImageRegistry().get(
						MyImageRegistry.PDA_WRITE_ICON);
			default:
				return MyImageRegistry.getImageRegistry().get(
						MyImageRegistry.CONTACT_ICON);				
		}
	}

	@Override
	/**
	 * Returns the data from the Contact which belongs to the given column. The
	 * column-index starts from zero.
	 */
	public String getColumnText(Object element, int columnIndex) {
		log.debug("Retrieving Column-text (index:" + columnIndex
				+ ") for Contact");
		
		switch(columnIndex) {		
		case 0:
			return ((Contact) element).toString();
		case 1:
			return ((Contact) element).getPrivateData().getPhoneNumber();
		case 2:
			return ((Contact) element).getOfficeData().getPhoneNumber();
		case 3:
			return ((Contact) element).getPrivateData().getEmail();
		default:
			return "";
		}
	}
}
